﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DemoObject;
using BusinessObjects;
using HTT.Utility;

public partial class Module_News_Controls_ItemNewsList : System.Web.UI.UserControl
{
    public string CategoryName { get; set; }
    public string CategoryTextId { get; set; }
    public int PageIndex
    {
        get
        {
            if (Request["page"] != null)
                return int.Parse(Request["page"].ToString());
            return 1;
        }
    }
    private const int PageSize = 20;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["CategoryTextId"] != null)
                CategoryTextId = Request["CategoryTextId"].ToString();
            TblCategory item = TblCategoryRepository.CreateInstant().SelectOne(CategoryTextId);
            if (item != null)
            {
                CategoryName = item.Name;
                int count = 0;
                HashSet<string> hs = new HashSet<string>();
                hs.Add("DisplayOrder ASC");
                hs.Add("CreatedDate DESC");
                IList<TblNews> ls = TblNewsRepository.CreateInstant().SelectListItem(null, item.Id, "", "", "", "", true, null, true, PageIndex, PageSize, out count, hs);
                rpt.DataSource = ls;
                rpt.DataBind();
                smartPager.PageSize = PageSize;
                smartPager.QueryStringKey = "page";
                smartPager.RowCount = count;
                smartPager.UrlFormatString = UrlBuilder.UrlListNewsPaging(CategoryTextId);
                smartPager.Visible = count > PageSize;
                if (ls != null && ls.Count > 0)
                {
                    SetTitle(ls[0].TblCategory);
                }
            }
        }
    }
    void SetTitle(TblCategory _item)
    {
        string title = _item.Name;
        string description = _item.Name;
        string keywords = _item.Name;
        MasterPage _page = this.Page.Master;
        WebUtility.SetPage(title, description, keywords, _page);
    }



}
